print("------------ 数组排序 ------------")
let names = ["zhangsan", "lisi", "wangwu", "zhaoliu"]
let sortedNames = names.sorted()
print(sortedNames)

print("------------ 数组逆序排序 ------------")
func backward(s1: String, s2: String) -> Bool {
    return s1 > s2
}
let sortedReverseNames = names.sorted(by: backward)
print(sortedReverseNames)

print("------------ 闭包表达式 ------------")
// 写法1
let sortedClosureNames1 = names.sorted(by: {
    (s1: String, s2: String) -> Bool in
    return s1 > s2
})
print(sortedClosureNames1)

// 写法2
let sortedClosureNames2 = names.sorted(by: {
    s1, s2 in
    return s1 > s2
})
print(sortedClosureNames2)

// 写法3
let sortedClosureNames3 = names.sorted(by: {
    s1, s2 in s1 > s2
})
print(sortedClosureNames3)

// 写法4
let sortedClosureNames4 = names.sorted(by: { $0 > $1 })
print(sortedClosureNames4)

// 写法5
let sortedClosureNames5 = names.sorted(by: > )
print(sortedClosureNames5)

// 尾随闭包
let sortedClosureNames6 = names.sorted{ $0 > $1 }
print(sortedClosureNames6)

print("------------ 闭包捕获值 ------------")
func incrementer(amount: Int) -> () -> Int {
    var total = 0
    func incrementer() -> Int {
        total += amount
        return total
    }
    return incrementer
}

let incrementer_ten = incrementer(amount: 10)
print(incrementer_ten())
print(incrementer_ten())
print(incrementer_ten())

let incrementer_seven = incrementer(amount: 7)
print(incrementer_seven())
print(incrementer_seven())
print(incrementer_seven())

// 闭包是引用类型
let incrementer_another_ten = incrementer_ten
print(incrementer_another_ten())

print("------------ |||| ------------")
var names1 = ["zhangsan", "lisi", "wangwu", "zhaoliu"]
let customerProvider = { names1.remove(at: 0) }
print(names1.count)
print(customerProvider())
print(names1.count)
